package net.lastcoder.ifserver.packet;

import net.lastcoder.ifserver.nio.UnauthorizedException;
import net.lastcoder.ifserver.session.Session;
import net.lastcoder.ifserver.session.UlaID;

/**ping 可以用来得到延迟
 * auth: WenYF
 * date: 2016/11/24
 */
public class PingHandler extends EventHandler {

    public PingHandler() {
        super("ping event handler", Event.PING_EVENT_TYPE);
    }

    @Override
    public void reload() {

    }

    @Override
    public boolean handle(Session session, Event packet) throws UnauthorizedException {
        if (packet.getType() != Event.TYPE_GET &&  packet.getType() != Event.TYPE_SET) {
            return true;
        }

        packet.setType(Event.TYPE_RESULT);
        UlaID from = packet.getFromAddress();
        packet.setFromAddress(packet.getToAddress());
        packet.setToAddress(from);

        session.process(packet);

        return true;
    }
}
